<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>测试七牛上传</title>
</head>
<body>
<script>
    window.config={
        qiniuUploadUrl:"http://up.qiniu.com",
        QINIUDomain: "//lims.demo.olab.top/",
    }
</script>
<script src="/config"></script><!-- 需要服务端运行得到配置，如七牛 -->
<script>
    if(runtimeConfig){
        Object.assign(config,runtimeConfig);//合并配置到window.config
    }
</script>
<form onsubmit="return upload(this)"
      enctype="multipart/form-data">
    <input name="file" type="file" />
    <input type="submit" value="上传文件" />
</form>
<script src="http://cdn.staticfile.org/axios/0.24.0/axios.js"></script>
<script>
    const getData = (resp) => resp.data;
    function upload(form){
        console.log("upload");
        const file=form.file.files[0];
        console.log(file);
        const originalName = file.name;
        console.log(originalName);
        const formdata = new FormData();
        formdata.append('token', config.upload_token);
        formdata.append('file', file, originalName);
        axios({
            url: config.qiniuUploadUrl,
            method: 'post',
            data: formdata,
        }).then(getData)
            .then(data => {
                data.url = config.QINIUDomain + data.key+`?attname=${originalName}`;
                console.log(data);
                document.getElementById("testUrl").href=data.url;
                document.getElementById("testUrl").innerText=originalName;
            });
        return false;
    }
</script>
<a id="testUrl" href="#">下载测试链接</a>
</body>
</html>